class NewsModel {
  final String id;
  final String title;
  final String content;
  final String imageUrl;
  final String category;
  final DateTime publishTime;
  final String author;
  final bool isTop;

  NewsModel({
    required this.id,
    required this.title,
    required this.content,
    required this.imageUrl,
    required this.category,
    required this.publishTime,
    required this.author,
    this.isTop = false,
  });

  factory NewsModel.fromJson(Map<String, dynamic> json) {
    return NewsModel(
      id: json['id'] as String,
      title: json['title'] as String,
      content: json['content'] as String,
      imageUrl: json['imageUrl'] as String,
      category: json['category'] as String,
      publishTime: DateTime.parse(json['publishTime'] as String),
      author: json['author'] as String,
      isTop: json.containsKey('isTop') ? json['isTop'] as bool : false,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'id': id,
      'title': title,
      'content': content,
      'imageUrl': imageUrl,
      'category': category,
      'publishTime': publishTime.toIso8601String(),
      'author': author,
      'isTop': isTop,
    };
  }
}
